/**
 * Beijing Jiaotong University
 * Copyright (c) 1896-2016 All Rights Reserved.
 */
package org.myws.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.myws.dao.mybatis.dao.UserMapper;
import org.myws.dao.mybatis.domain.User;
import org.myws.service.UserService;
import org.myws.service.common.facade.dto.PageDTO;
import org.myws.service.common.util.AssertUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

/**
 * 
 * @author HuHui
 * @version $Id: UserServiceImpl.java, v 0.1 2016年5月7日 下午8:49:55 HuHui Exp $
 */
@Service
public class UserServiceImpl implements UserService {

    private static final Logger log = LoggerFactory.getLogger(UserServiceImpl.class);

    @Resource
    private UserMapper          userMapper;

    /** 
     * @see org.myws.service.UserService#getUserById(java.lang.Long)
     */
    @Override
    public User getUserById(Long id) {
        log.info("收到查询User条件,id={}", id);

        AssertUtil.assertNotNull(id, "查询参数id为空");

        User user = userMapper.selectByPrimaryKey(id);

        log.info("User查询结果,user={}", JSON.toJSONString(user));
        return user;
    }

    @Override
    public PageDTO<User> getUser(int pageNum, int pageSize) {

        log.info("收到查询User列表参数, pageNum={}, pageSize={}", pageNum, pageSize);

        AssertUtil.assertNotNull(pageNum, "查询参数pageNum为空");
        AssertUtil.assertNotNull(pageSize, "查询参数pageSize为空");

        PageDTO<User> pageDTO = new PageDTO<User>();

        PageHelper.startPage(pageNum, pageSize);
        List<User> users = userMapper.selectAll();
        PageInfo<User> pageInfo = new PageInfo<User>(users);

        pageDTO.setData(users);
        pageDTO.setPageInfo(pageInfo);

        return pageDTO;
    }

}
